package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by 嗨哟 on 2017/4/6.
 */
public class MyGoldMasterAdapter extends RecyclerView.Adapter<MyGoldMasterAdapter.GoldMasterViewHolder> {
    private Context context;
    private List<?> list;
    private LayoutInflater layoutInflater;

    public MyGoldMasterAdapter(Context context, List<?> list) {
        this.context = context;
        this.list = list;
        layoutInflater=LayoutInflater.from(context);
    }

    public void UpData(List<?> list){
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public GoldMasterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=layoutInflater.inflate(R.layout.my_gold_master_item,parent,false);
        AutoUtils.autoSize(view);
        return new GoldMasterViewHolder(view);
    }

    @Override
    public void onBindViewHolder(GoldMasterViewHolder holder, int position) {
        holder.position=position;
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    class GoldMasterViewHolder extends RecyclerView.ViewHolder{
        int position;
        ImageView gold_master_item_image;
        TextView gold_master_item_name,gold_master_item_rezheng,gold_master_item_classify,
                gold_master_item_dengji,gold_master_item_guanzhu;
        RatingBar gold_master_item_haoping;
        public GoldMasterViewHolder(View itemView) {
            super(itemView);
            gold_master_item_image= (ImageView) itemView.findViewById(R.id.gold_master_item_image);
            gold_master_item_name= (TextView) itemView.findViewById(R.id.gold_master_item_name);
            gold_master_item_rezheng= (TextView) itemView.findViewById(R.id.gold_master_item_rezheng);
            gold_master_item_classify= (TextView) itemView.findViewById(R.id.gold_master_item_classify);
            gold_master_item_dengji= (TextView) itemView.findViewById(R.id.gold_master_item_dengji);
            gold_master_item_guanzhu= (TextView) itemView.findViewById(R.id.gold_master_item_guanzhu);
            gold_master_item_haoping= (RatingBar) itemView.findViewById(R.id.gold_master_item_haoping);
            gold_master_item_guanzhu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String text=gold_master_item_guanzhu.getText().toString();
                    if(text.equals("+ 关注")){
                        gold_master_item_guanzhu.setText("已关注");
                    }else{
                        gold_master_item_guanzhu.setText("+ 关注");
                    }
                }
            });
        }
    }
}
